package com.gable.exhibition.init;

import com.alibaba.fastjson.JSON;
import com.gable.exhibition.dao.ManufacturerDao;
import com.gable.exhibition.dao.ManufacturerMaintainerDao;
import com.gable.exhibition.model.Maintainer;
import com.gable.exhibition.view.MaintainerView;
import com.gable.exhibition.view.ManufacturerMaintainerView;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lesson on 2018/3/3.
 */
@Component
public class ManufacturerInit {

        Logger logger = Logger.getLogger(this.getClass());

        @Autowired
        ManufacturerMaintainerDao manufacturerMaintainerDao;


        public static Map<Long,ManufacturerMaintainerView> manufacturerMaintainerMap = null;


        public void queryManufacturerMaintainer(){
            logger.debug("厂商和维修商之间的关系初始化开始");
            if(manufacturerMaintainerMap == null){
                manufacturerMaintainerMap = new HashMap<Long,ManufacturerMaintainerView>();
            }

            List<ManufacturerMaintainerView> list =  manufacturerMaintainerDao.manufacturerMaintainerInit();
            for(ManufacturerMaintainerView mm : list){
                Long manufacturerId = mm.getManufacturerId();
                manufacturerMaintainerMap.put(manufacturerId,mm);
            }
            logger.debug("厂商和维修商之间的关系初始化结束");
            logger.debug("结果集："+ JSON.toJSONString(manufacturerMaintainerMap));
        }


        public void updateManufacturerMaintainer(){
            queryManufacturerMaintainer();
        }

}
